package name.wilbur.course.db.bigone.dao.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import name.wilbur.course.db.bigone.dao.BaseDAO;
import name.wilbur.course.db.bigone.model.Occupation;



/**
 * @author wilbur
 */
public class OccupationDAO extends BaseDAO implements IOccupationDAO {
	public OccupationDAO() {
		super(Occupation.class);
	}
	
	public Map<String, String> findOccupations(String str) {
		String sql = "SELECT OccupationID, OccupationName FROM " + table;
		String sqlCnt = "SELECT COUNT(OccupationID) FROM " + table;
		Map<String, String> NameID = null;
		try {
			if (str==null) {
				/* get all cities */
				queryNotClose(sqlCnt);
				if (rs.next())
					NameID = new HashMap<String, String>(rs.getInt(1));
				if (NameID == null)
					log().error("NameID is null");
				closeConnection();
				queryNotClose(sql);
				while (rs.next()) {
					NameID.put(rs.getString(1), rs.getString(2));
				}
				closeConnection();
			} else {
				/* not implemented now */
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return NameID;
	}
}
